Public Class frmOption
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
  Friend WithEvents tbControl As System.Windows.Forms.TabControl
  Friend WithEvents tabGeneral As System.Windows.Forms.TabPage
  Friend WithEvents btnApply As System.Windows.Forms.Button
  Friend WithEvents btnCancel As System.Windows.Forms.Button
  Friend WithEvents chkAutoCheck As System.Windows.Forms.CheckBox
  Friend WithEvents lblPort As System.Windows.Forms.Label
  Friend WithEvents ntxtPort As System.Windows.Forms.NumericUpDown
  Friend WithEvents lblDefaultName As System.Windows.Forms.Label
  Friend WithEvents txtDefaultName As System.Windows.Forms.TextBox
  Friend WithEvents lblOpacity As System.Windows.Forms.Label
  Friend WithEvents ntxtOpacity As System.Windows.Forms.NumericUpDown
  Friend WithEvents tpSound As System.Windows.Forms.TabPage
  Friend WithEvents txtSoundMove As System.Windows.Forms.TextBox
  Friend WithEvents btnSoundMove As System.Windows.Forms.Button
  Friend WithEvents lblMoveSound As System.Windows.Forms.Label
  Friend WithEvents txtSoundPromotion As System.Windows.Forms.TextBox
  Friend WithEvents btnSoundPromotion As System.Windows.Forms.Button
  Friend WithEvents lblSoundPromote As System.Windows.Forms.Label
  Friend WithEvents txtSoundCut As System.Windows.Forms.TextBox
  Friend WithEvents btnSoundCut As System.Windows.Forms.Button
  Friend WithEvents lblSoundCut As System.Windows.Forms.Label
  Friend WithEvents odSound As System.Windows.Forms.OpenFileDialog
  Friend WithEvents Label1 As System.Windows.Forms.Label
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.tbControl = New System.Windows.Forms.TabControl
    Me.tabGeneral = New System.Windows.Forms.TabPage
    Me.Label1 = New System.Windows.Forms.Label
    Me.ntxtOpacity = New System.Windows.Forms.NumericUpDown
    Me.lblOpacity = New System.Windows.Forms.Label
    Me.txtDefaultName = New System.Windows.Forms.TextBox
    Me.lblDefaultName = New System.Windows.Forms.Label
    Me.ntxtPort = New System.Windows.Forms.NumericUpDown
    Me.lblPort = New System.Windows.Forms.Label
    Me.chkAutoCheck = New System.Windows.Forms.CheckBox
    Me.tpSound = New System.Windows.Forms.TabPage
    Me.txtSoundPromotion = New System.Windows.Forms.TextBox
    Me.btnSoundPromotion = New System.Windows.Forms.Button
    Me.lblSoundPromote = New System.Windows.Forms.Label
    Me.txtSoundCut = New System.Windows.Forms.TextBox
    Me.btnSoundCut = New System.Windows.Forms.Button
    Me.lblSoundCut = New System.Windows.Forms.Label
    Me.txtSoundMove = New System.Windows.Forms.TextBox
    Me.btnSoundMove = New System.Windows.Forms.Button
    Me.lblMoveSound = New System.Windows.Forms.Label
    Me.btnApply = New System.Windows.Forms.Button
    Me.btnCancel = New System.Windows.Forms.Button
    Me.odSound = New System.Windows.Forms.OpenFileDialog
    Me.tbControl.SuspendLayout()
    Me.tabGeneral.SuspendLayout()
    CType(Me.ntxtOpacity, System.ComponentModel.ISupportInitialize).BeginInit()
    CType(Me.ntxtPort, System.ComponentModel.ISupportInitialize).BeginInit()
    Me.tpSound.SuspendLayout()
    Me.SuspendLayout()
    '
    'tbControl
    '
    Me.tbControl.Controls.Add(Me.tabGeneral)
    Me.tbControl.Controls.Add(Me.tpSound)
    Me.tbControl.Location = New System.Drawing.Point(0, 0)
    Me.tbControl.Name = "tbControl"
    Me.tbControl.SelectedIndex = 0
    Me.tbControl.Size = New System.Drawing.Size(368, 168)
    Me.tbControl.TabIndex = 0
    '
    'tabGeneral
    '
    Me.tabGeneral.Controls.Add(Me.Label1)
    Me.tabGeneral.Controls.Add(Me.ntxtOpacity)
    Me.tabGeneral.Controls.Add(Me.lblOpacity)
    Me.tabGeneral.Controls.Add(Me.txtDefaultName)
    Me.tabGeneral.Controls.Add(Me.lblDefaultName)
    Me.tabGeneral.Controls.Add(Me.ntxtPort)
    Me.tabGeneral.Controls.Add(Me.lblPort)
    Me.tabGeneral.Controls.Add(Me.chkAutoCheck)
    Me.tabGeneral.Location = New System.Drawing.Point(4, 22)
    Me.tabGeneral.Name = "tabGeneral"
    Me.tabGeneral.Size = New System.Drawing.Size(360, 142)
    Me.tabGeneral.TabIndex = 0
    Me.tabGeneral.Text = "General"
    Me.tabGeneral.UseVisualStyleBackColor = True
    '
    'Label1
    '
    Me.Label1.AutoSize = True
    Me.Label1.Location = New System.Drawing.Point(208, 116)
    Me.Label1.Name = "Label1"
    Me.Label1.Size = New System.Drawing.Size(15, 13)
    Me.Label1.TabIndex = 8
    Me.Label1.Text = "%"
    '
    'ntxtOpacity
    '
    Me.ntxtOpacity.Location = New System.Drawing.Point(160, 112)
    Me.ntxtOpacity.Name = "ntxtOpacity"
    Me.ntxtOpacity.Size = New System.Drawing.Size(48, 20)
    Me.ntxtOpacity.TabIndex = 7
    '
    'lblOpacity
    '
    Me.lblOpacity.AutoSize = True
    Me.lblOpacity.Location = New System.Drawing.Point(24, 112)
    Me.lblOpacity.Name = "lblOpacity"
    Me.lblOpacity.Size = New System.Drawing.Size(72, 13)
    Me.lblOpacity.TabIndex = 6
    Me.lblOpacity.Text = "Transparency"
    '
    'txtDefaultName
    '
    Me.txtDefaultName.Location = New System.Drawing.Point(160, 80)
    Me.txtDefaultName.Name = "txtDefaultName"
    Me.txtDefaultName.Size = New System.Drawing.Size(136, 20)
    Me.txtDefaultName.TabIndex = 5
    '
    'lblDefaultName
    '
    Me.lblDefaultName.AutoSize = True
    Me.lblDefaultName.Location = New System.Drawing.Point(24, 80)
    Me.lblDefaultName.Name = "lblDefaultName"
    Me.lblDefaultName.Size = New System.Drawing.Size(104, 13)
    Me.lblDefaultName.TabIndex = 4
    Me.lblDefaultName.Text = "Default Player Name"
    '
    'ntxtPort
    '
    Me.ntxtPort.Location = New System.Drawing.Point(160, 44)
    Me.ntxtPort.Maximum = New Decimal(New Integer() {65000, 0, 0, 0})
    Me.ntxtPort.Name = "ntxtPort"
    Me.ntxtPort.Size = New System.Drawing.Size(80, 20)
    Me.ntxtPort.TabIndex = 3
    Me.ntxtPort.Value = New Decimal(New Integer() {1001, 0, 0, 0})
    '
    'lblPort
    '
    Me.lblPort.AutoSize = True
    Me.lblPort.Location = New System.Drawing.Point(24, 48)
    Me.lblPort.Name = "lblPort"
    Me.lblPort.Size = New System.Drawing.Size(101, 13)
    Me.lblPort.TabIndex = 2
    Me.lblPort.Text = "Network Port to use"
    '
    'chkAutoCheck
    '
    Me.chkAutoCheck.Checked = True
    Me.chkAutoCheck.CheckState = System.Windows.Forms.CheckState.Checked
    Me.chkAutoCheck.Location = New System.Drawing.Point(29, 16)
    Me.chkAutoCheck.Name = "chkAutoCheck"
    Me.chkAutoCheck.Size = New System.Drawing.Size(192, 24)
    Me.chkAutoCheck.TabIndex = 1
    Me.chkAutoCheck.Text = "Allow Auto Version Check Online"
    '
    'tpSound
    '
    Me.tpSound.Controls.Add(Me.txtSoundPromotion)
    Me.tpSound.Controls.Add(Me.btnSoundPromotion)
    Me.tpSound.Controls.Add(Me.lblSoundPromote)
    Me.tpSound.Controls.Add(Me.txtSoundCut)
    Me.tpSound.Controls.Add(Me.btnSoundCut)
    Me.tpSound.Controls.Add(Me.lblSoundCut)
    Me.tpSound.Controls.Add(Me.txtSoundMove)
    Me.tpSound.Controls.Add(Me.btnSoundMove)
    Me.tpSound.Controls.Add(Me.lblMoveSound)
    Me.tpSound.Location = New System.Drawing.Point(4, 22)
    Me.tpSound.Name = "tpSound"
    Me.tpSound.Size = New System.Drawing.Size(360, 142)
    Me.tpSound.TabIndex = 1
    Me.tpSound.Text = "Sound"
    Me.tpSound.UseVisualStyleBackColor = True
    '
    'txtSoundPromotion
    '
    Me.txtSoundPromotion.Location = New System.Drawing.Point(150, 62)
    Me.txtSoundPromotion.Name = "txtSoundPromotion"
    Me.txtSoundPromotion.Size = New System.Drawing.Size(173, 20)
    Me.txtSoundPromotion.TabIndex = 8
    '
    'btnSoundPromotion
    '
    Me.btnSoundPromotion.Location = New System.Drawing.Point(328, 60)
    Me.btnSoundPromotion.Name = "btnSoundPromotion"
    Me.btnSoundPromotion.Size = New System.Drawing.Size(26, 23)
    Me.btnSoundPromotion.TabIndex = 7
    Me.btnSoundPromotion.Text = "..."
    Me.btnSoundPromotion.UseVisualStyleBackColor = True
    '
    'lblSoundPromote
    '
    Me.lblSoundPromote.AutoSize = True
    Me.lblSoundPromote.Location = New System.Drawing.Point(7, 66)
    Me.lblSoundPromote.Name = "lblSoundPromote"
    Me.lblSoundPromote.Size = New System.Drawing.Size(133, 13)
    Me.lblSoundPromote.TabIndex = 6
    Me.lblSoundPromote.Text = "Sound on Pawn Promotion"
    '
    'txtSoundCut
    '
    Me.txtSoundCut.Location = New System.Drawing.Point(151, 36)
    Me.txtSoundCut.Name = "txtSoundCut"
    Me.txtSoundCut.Size = New System.Drawing.Size(173, 20)
    Me.txtSoundCut.TabIndex = 5
    '
    'btnSoundCut
    '
    Me.btnSoundCut.Location = New System.Drawing.Point(329, 34)
    Me.btnSoundCut.Name = "btnSoundCut"
    Me.btnSoundCut.Size = New System.Drawing.Size(26, 23)
    Me.btnSoundCut.TabIndex = 4
    Me.btnSoundCut.Text = "..."
    Me.btnSoundCut.UseVisualStyleBackColor = True
    '
    'lblSoundCut
    '
    Me.lblSoundCut.AutoSize = True
    Me.lblSoundCut.Location = New System.Drawing.Point(8, 40)
    Me.lblSoundCut.Name = "lblSoundCut"
    Me.lblSoundCut.Size = New System.Drawing.Size(102, 13)
    Me.lblSoundCut.TabIndex = 3
    Me.lblSoundCut.Text = "Sound on Piece Cut"
    '
    'txtSoundMove
    '
    Me.txtSoundMove.Location = New System.Drawing.Point(151, 10)
    Me.txtSoundMove.Name = "txtSoundMove"
    Me.txtSoundMove.Size = New System.Drawing.Size(173, 20)
    Me.txtSoundMove.TabIndex = 2
    '
    'btnSoundMove
    '
    Me.btnSoundMove.Location = New System.Drawing.Point(329, 8)
    Me.btnSoundMove.Name = "btnSoundMove"
    Me.btnSoundMove.Size = New System.Drawing.Size(26, 23)
    Me.btnSoundMove.TabIndex = 1
    Me.btnSoundMove.Text = "..."
    Me.btnSoundMove.UseVisualStyleBackColor = True
    '
    'lblMoveSound
    '
    Me.lblMoveSound.AutoSize = True
    Me.lblMoveSound.Location = New System.Drawing.Point(8, 14)
    Me.lblMoveSound.Name = "lblMoveSound"
    Me.lblMoveSound.Size = New System.Drawing.Size(136, 13)
    Me.lblMoveSound.TabIndex = 0
    Me.lblMoveSound.Text = "Sound on Piece Movement"
    '
    'btnApply
    '
    Me.btnApply.Location = New System.Drawing.Point(272, 176)
    Me.btnApply.Name = "btnApply"
    Me.btnApply.Size = New System.Drawing.Size(88, 32)
    Me.btnApply.TabIndex = 1
    Me.btnApply.Text = "&Apply"
    '
    'btnCancel
    '
    Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
    Me.btnCancel.Location = New System.Drawing.Point(152, 176)
    Me.btnCancel.Name = "btnCancel"
    Me.btnCancel.Size = New System.Drawing.Size(96, 32)
    Me.btnCancel.TabIndex = 2
    Me.btnCancel.Text = "&Cancel"
    '
    'odSound
    '
    Me.odSound.Filter = "Wave Files|*.wav|Mp3 Files|*.mp3"
    '
    'frmOption
    '
    Me.AcceptButton = Me.btnApply
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.CancelButton = Me.btnCancel
    Me.ClientSize = New System.Drawing.Size(368, 215)
    Me.Controls.Add(Me.btnCancel)
    Me.Controls.Add(Me.btnApply)
    Me.Controls.Add(Me.tbControl)
    Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
    Me.MaximizeBox = False
    Me.MinimizeBox = False
    Me.Name = "frmOption"
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
    Me.Text = "VS ChessMania v2 Options"
    Me.tbControl.ResumeLayout(False)
    Me.tabGeneral.ResumeLayout(False)
    Me.tabGeneral.PerformLayout()
    CType(Me.ntxtOpacity, System.ComponentModel.ISupportInitialize).EndInit()
    CType(Me.ntxtPort, System.ComponentModel.ISupportInitialize).EndInit()
    Me.tpSound.ResumeLayout(False)
    Me.tpSound.PerformLayout()
    Me.ResumeLayout(False)

  End Sub

#End Region

  Private t_opacityValue As Integer
  Private tmpOpacity As Integer

  Public Property OpacityValue() As Integer
    Get
      Return t_opacityValue
    End Get
    Set(ByVal Value As Integer)
      t_opacityValue = Value
    End Set
  End Property

  Private Sub btnApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApply.Click
    Try
      Me.OpacityValue = CInt(ntxtOpacity.Value)
      AppConfig.SetValue("Settings", "Port", Me.ntxtPort.Value.ToString)
      AppConfig.SetValue("GamePlay", "DefaultName", Me.txtDefaultName.Text)
      If chkAutoCheck.Checked Then
        AppConfig.SetValue("Settings", "AutoUpdateEnable", "1")
      Else
        AppConfig.SetValue("Settings", "AutoUpdateEnable", "0")
      End If
      AppConfig.SetValue("Sound", "MoveCommitted", txtSoundMove.Text)
      AppConfig.SetValue("Sound", "PawnPromotion", txtSoundPromotion.Text)
      AppConfig.SetValue("Sound", "PawnCut", txtSoundCut.Text)
    Catch ex As Exception
      MsgBox("Fail to set configuration file")
    End Try
    Me.DialogResult = Windows.Forms.DialogResult.OK
    Me.Hide()
  End Sub

  Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
    Me.DialogResult = Windows.Forms.DialogResult.Cancel
    Me.Hide()
  End Sub

  Private Sub frmOption_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Try
      ntxtOpacity.Value = Me.OpacityValue
      Me.ntxtPort.Value = CInt(AppConfig.GetValue("Settings", "Port"))
      Me.txtDefaultName.Text = AppConfig.GetValue("GamePlay", "DefaultName")
      If IsNumeric(AppConfig.GetValue("Settings", "AutoUpdateEnable")) AndAlso AppConfig.GetValue("Settings", "AutoUpdateEnable") = "1" Then
        Me.chkAutoCheck.Checked = True
      Else
        Me.chkAutoCheck.Checked = False
      End If
      txtSoundMove.Text = AppConfig.GetValue("Sound", "MoveCommitted")
      txtSoundPromotion.Text = AppConfig.GetValue("Sound", "PawnPromotion")
      txtSoundCut.Text = AppConfig.GetValue("Sound", "PawnCut")
    Catch
    End Try
  End Sub

  Private Sub ntxtOpacity_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ntxtOpacity.ValueChanged
    tmpOpacity = CInt(ntxtOpacity.Value)
  End Sub

  Private Sub btnSoundMove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSoundMove.Click, btnSoundCut.Click, btnSoundPromotion.Click
    odSound.FileName = ""
    odSound.ShowDialog()
    Dim btnName As Button
    btnName = CType(sender, Button)
    If Trim(odSound.FileName) <> "" Then
      Select Case btnName.Name
        Case "btnSoundMove"
          txtSoundMove.Text = odSound.FileName
          AppConfig.SetValue("Sound", "MoveCommitted", txtSoundMove.Text)
        Case "btnSoundPromotion"
          txtSoundPromotion.Text = odSound.FileName
          AppConfig.SetValue("Sound", "PawnPromotion", txtSoundPromotion.Text)
        Case "btnSoundCut"
          txtSoundCut.Text = odSound.FileName
          AppConfig.SetValue("Sound", "PawnCut", txtSoundCut.Text)
      End Select
    End If
  End Sub
End Class
